package com.cjg.scrolldemo;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.cjg.scrolldemo.databinding.ItemCPersonTab1Binding;
import java.util.List;

public class CPersonTab1Adapter extends RecyclerView.Adapter<CPersonTab1Adapter.ViewHolder> {
    private List<String> dataList;
    private ItemCPersonTab1Binding bidning;

    CPersonTab1Adapter(List<String> dataList) {
        this.dataList = dataList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_c_person_tab1, parent, false);
        bidning= DataBindingUtil.bind(view);//使用DataBind
        return new ViewHolder(view);//return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        String content = dataList.get(position);
        bidning.tv.setText(content);
    }

    @Override
    public int getItemCount() {
        return dataList == null ? 0 : dataList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
